Fruit = {x = 0, y = 0, i = 0, t = 10}

local fruitSprite = lg.newImage("fruit.png")
local starSprire = lg.newImage("star.png")

function Fruit:new()
	local fruit = {} or Fruit
	fruit.y = -10
	fruit.x = love.math.random(50, lg.getWidth() - 50)
    fruit.shell = false
    fruit.crunch = false
    fruit.slowmo = false
    local chance = love.math.random() 
   if chance >= .05 and chance < .1 then
      fruit.shell = true
   elseif chance >= .03 and chance < .05 then
      fruit.crunch = true
    elseif chance >= .01 and chance < .03 then
        fruit.slowmo = true
   end
    if fruit.slowmo or fruit.crunch or fruit.shell then
        fruit.sprite = starSprire
    else
        fruit.sprite = fruitSprite
    end
	setmetatable(fruit,self)
	self.__index = self
	table.insert(fruits, fruit)
	return fruit
end

function Fruit.update(self, dt)
    if not timers.crunch.isStopped and distance(points[1],points[2], self.x, self.y) < 20 then
      eatFruit(self)
    end
	if self.y > lg.getHeight() then 
        local i = table.find(fruits,self)
        table.remove(fruits, i) 
    end
	self.y = self.y + 20 * dt * speedMultiplier
end

function Fruit.draw(self)
    if self.shell then
        lg.setColor({52/255,160/255,56/255})
    elseif self.crunch then
        lg.setColor({164/255,12/255,44/255})
    elseif self.slowmo then
        lg.setColor({79/255,64/255,207/255})
    end
    lg.draw(self.sprite, self.x - 10, self.y - 10)      
    lg.setColor(1,1,1)
end

return Fruit
